package top.withu.gaof.freehope;

import org.apache.tomcat.util.collections.SynchronizedQueue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Gaofan
 * @date 2019年3月21日 下午4:44:44
 * @describe
 */

@SpringBootApplication
@EnableSwagger2
public class FHApplication extends SpringBootServletInitializer {

	public static void main(String[] args) {
		SpringApplication.run(FHApplication.class, args);
	}

	/**
	 * 解决前后端分离跨域问题
	 *
	 * @return
	 */
	@Bean
	public CorsFilter corsFilter() {
		final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		final CorsConfiguration config = new CorsConfiguration();
		config.setAllowCredentials(true);
		config.addAllowedOrigin("*");
		config.addAllowedHeader("*");
		config.addAllowedMethod("*");
		source.registerCorsConfiguration("/**", config);
		return new CorsFilter(source);
	}

}
